package com.ctfo.ulcp.exp.core

import dev.langchain4j.data.document.Metadata
import dev.langchain4j.data.embedding.Embedding
import dev.langchain4j.data.segment.TextSegment
import dev.langchain4j.model.embedding.BgeSmallZhQuantizedEmbeddingModel
import dev.langchain4j.model.embedding.EmbeddingModel
//import dev.langchain4j.store.embedding.weaviate.WeaviateEmbeddingStore

fun main() {

    val embeddingModel: EmbeddingModel = BgeSmallZhQuantizedEmbeddingModel()

    val text = "今天是星期一"


    val segment = TextSegment.from(text, Metadata.metadata("res_id", "457"))
    val embedding = embeddingModel.embed(segment).content()

    val embeddingStore = WeaviateEmbeddingStore(
        "",
        "http",
        "172.20.60.5",
        8080,
        "Test02",
        true,
        "ALL",
        listOf("res_id","res_type")
    )
//
//    val embeddingStore = WeaviateEmbeddingStore.builder()
//        .apiKey("")
//        .scheme("http")
//        .host("172.20.60.5:8080")
//        .objectClass("Test02")
//        .avoidDups(true)
//        .consistencyLevel("ALL")
//        .build()

    embeddingStore.add(embedding, segment)

    val queryEmbedding: Embedding = embeddingModel.embed("今天是什么日子").content()
    val relevant = embeddingStore.findRelevant(queryEmbedding, 20)

    println("match size: ${relevant.size}")
    for (match in relevant) {
        println(match.score())
        println(match.embedded().text())
        println(match.embedded().metadata())
    }

}
